package com.arc.spring.ioc.lifecycle;

import com.arc.spring.entity.Person;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 后置通知
 */
public class MyBeanPostProcessor implements BeanPostProcessor {

    /**
     * bean 初始化之前
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        Person person = (Person) bean;
        if(person.getSex().equals("男")) {
            person.setName("张无忌");
        } else {
            person.setName("赵敏");
        }
        return person;
    }

    /**
     * bean 初始化之后
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
